package org.geektimes.configuration.microprofile.config.sources.servlet;

import java.util.Enumeration;
import java.util.Map;

import javax.servlet.ServletContext;

import org.geektimes.configuration.microprofile.config.sources.MappedAbstractConfigSource;

public class ServletContextConfigSource extends MappedAbstractConfigSource {

	private ServletContext servletContext;

	public ServletContextConfigSource(ServletContext servletContext) {
		super(400, "Servlete-Context-Config", false);
		this.servletContext = servletContext;
		this.getProperties();
	}

	@Override
	protected void prepareProperties(Map<String, String> properties) throws Throwable {
		Enumeration<String> names = servletContext.getInitParameterNames();

		while (names.hasMoreElements()) {
			String name = names.nextElement();
			properties.put(name, servletContext.getInitParameter(name));
		}

	}

}
